﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace BGSpaceShooterServer
{
    internal class Projectile : ICollidable
    {
        public int Id { get; set; }
        public int PlayerId { get; set; } //Zeby wiedziec kto zabil
        private int hp;
        public int HP
        {
            get
            {
                return hp;
            }
            set
            {
                if (value <= 0 && hp > 0)
                {
                    IsAlive = false;
                    IsZombie = true;
                }
                hp = value;
            }
        }
        public bool IsAlive { get; set; }
        public bool IsZombie { get; set; }
        public Vector3 Position { get; set; }
        public Vector3 Velocity { get; set; }
        public Matrix Rotation { get; set; }
        public GameObjectName ProjectileType { get; set; }
        public DateTime CreatedTime { get; set; }
        public BoundingSphere BoundingSphere { get; set; }

        /// <summary>
        /// Ostatnie przesuniecie
        /// </summary>
        public Vector3 LastPositionDelta { get; set; }

        public Projectile()
        {
            ProjectileType = GameObjectName.Asteroid;
            LastPositionDelta = Vector3.Zero;
            IsZombie = false;
        }

        public void UpdatePosition(TimeSpan time)
        {
            LastPositionDelta = Convert.ToSingle(time.TotalMilliseconds) * Velocity;

            Position += LastPositionDelta;
        }
    }
}
